package com.shchekoldin.server.util;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;

public class FileContentReader {

    private static final int BUFFER_SIZE = 10240;

    // -------------------------------------------------------
    // LOGIC
    // -------------------------------------------------------

    //
    // API
    //

    public static String run(String fileName) throws IOException {
        StringBuilder result = new StringBuilder();
        Reader fileReader = new InputStreamReader(new FileInputStream(fileName), "utf-8");

        char[] buffer = new char[BUFFER_SIZE];
        int bytesRead = fileReader.read(buffer);

        while (bytesRead != -1) {
            result.append(buffer, 0, bytesRead);
            bytesRead = fileReader.read(buffer);
        }

        fileReader.close();

        return result.toString();
    }

}
